package com.pansoft.openplanet.util;

import com.efounder.constant.EnvironmentVariable;
import com.pansoft.hd.BIP44Util;
import com.pansoft.hd.HDWalletUtil;
import com.utilcode.util.LogUtils;

import org.bitcoinj.core.NetworkParameters;

public class BtcNetParamUtil {

    public static final String BASE_URL = EnvironmentVariable.getProperty("TalkChainUrl") + "/tcserver";

    private static String bipPath = BIP44Util.BITCOIN_MAINNET_PATH;
//    private static String bipPath = BIP44Util.BITCOIN_TESTNET_PATH;
    //获取余额
    public static final String URL_BTC_GET_BALANCE = BASE_URL + "/btc/btcGetBalance";
    //获取utxo
    public static final String URL_BTC_GET_UTXO = BASE_URL + "/btc/btcGetUtxo";
    //获取推荐手续费
    public static final String URL_BTC_GET_RECOMMENDBTC_FEES = BASE_URL + "/btc/getRecommendBtcFees";
    //广播交易
    public static final String URL_BTC_PUBLISH = BASE_URL + "/btc/publish";
    //交易记录
    public static final String URL_BTC_TX_HISTORY = BASE_URL + "/btc/getAddressTxs";
    //正式或测试网络
        public static final String NET_TYPE = "formal";
//    public static final String NET_TYPE = "test";
    public static NetworkParameters getBtcNetParams(){
        //正式或测试网络
        return HDWalletUtil.getNetworkParameters();
    }

    /**
     * 获取创建不同btc钱包的bip协议
     * btc需要在bip44和bip49之间转换
     * eth的统一为bip44
     */
    public static String getBtcBipPath() {
        return bipPath;
    }

    public static void setBtcBipPath(String bipPath) {
        BtcNetParamUtil.bipPath = bipPath;
    }

    /**
     * 估算btc交易的大小
     * @param inputNum 输入数量
     * @param outputNum 输出数量
     * @return 大小， 单位字节
     */
    public static int computeBtcTxSize(int inputNum, int outputNum) {
        int size = inputNum * 148 + outputNum * 34 + 10;
        LogUtils.d("估算的交易大小", size);
        return size;
    }
}
